home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 668 < prev    next >
Encoding:
Text File  |  1996-08-06  |  3.3 KB  |  73 lines

  1. Path: chronicle.mti.sgi.com!austern
  2. From: kanze@gabi-soft.fr (J. Kanze)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Streams and eof()
  5. Date: 08 Mar 1996 09:08:56 PST
  6. Organization: GABI Software, Sarl.
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <KANZE.96Mar8124126@gabi.gabi-soft.fr>
  9. References: <4hgap6$6o7@fu-berlin.de> <4hkean$mrc@engnews1.Eng.Sun.COM>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 08 Mar 1996 11:41:26 GMT
  12. In-reply-to: clamage@Eng.Sun.COM's message of 07 Mar 96 13:40:54 GMT
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMUBpuEy4NqrwXLNJAQHkFAH/eWdYdZrolAeCL59HFgV4TYX8D8dkximn
  15.     D4XvlT8tEhZf/KqC25fmNpW4zCALHTQ90w+WPuIcRLYqkq3oGqG4BA==
  16.     =oxej
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. In article <4hkean$mrc@engnews1.Eng.Sun.COM> clamage@Eng.Sun.COM (Steve
  20. Clamage) writes:
  21.  
  22. |> No, it must work. EOF is required to have a value different from every
  23. |> character value.
  24.  
  25. Where does it say this?  (It's what I always thought too, until a recent
  26. discussion in comp.std.c proved me otherwise, at least for C.)
  27.  
  28. It is indirectly required if INT_MAX >= UCHAR_MAX, at least for fgetc in
  29. C, but if int's and char's are the same size, all bets are off.
  30.  
  31. By `character value', I presume you mean a value that can be returned by
  32. a successful read, since the original question concerned using
  33. istream::peek and istream::get for binary input.  Although even for
  34. character (non-binary) input, I can see no guarantees once one leaves
  35. the "C" locale.
  36.  
  37. |> The character-reading functions that can return either
  38. |> a character or EOF return a type that that can represent the EOF value
  39. |> as distinct from any character value.
  40.  
  41. This is definitly not the case in ISO C, and I can find no such
  42. guarantee in the current draft either, although in this case, it might
  43. be a simple oversight.  Again, there is some ambiguity in your use of
  44. the word character: imagine a 16 bit machine with sizeof( int ) ==
  45. sizeof( char ) == 1, using Unicode as its native character code.
  46. Unicode explicitly doesn't use 0xFFFF (-1) as a legal code, so if EOF is
  47. -1 (a frequent implementation), there is no problem with reading
  48. `characters'.  Reading a `char' from a file opened in binary mode is
  49. still a problem, however.
  50.  
  51. |> In a traditional implementation, EOF has the int value -1, and characters
  52. |> have 8-bit values. The peek function returns the character value promoted
  53. |> to type int without sign extension, as if by the cast sequence
  54. |>     (int)(unsigned char)the_value
  55. |> Such a value cannot compare equal to the int value -1.
  56.  
  57. I suspect that a lot of code developed on a traditional implementation
  58. will break on a machine where all integral types are the same length.
  59. (I know that a lot of mine would.  Even in the parts I thought I wrote
  60. portably.)
  61. -- 
  62. James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
  63. GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
  64. Conseils, Θtudes et rΘalisations en logiciel orientΘ objet --
  65.               -- A la recherche d'une activitΘ dans une region francophone
  66. ---
  67. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  68.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  69.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  70.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  71.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  72. ]
  73.